"""
序列化：把一个对象变成字符串（str）或者字节串（bytes）
反序列化：把字符串或者字节串还原成对象
json - dumps / loads - 字符串
pickle - dumps / loads - 字节串
"""
import pickle

import redis


class Student(object):

    def __init__(self, stuid, name, sex, addr):
        self.stuid = stuid
        self.name = name
        self.sex = sex
        self.addr = addr

    def __repr__(self):
        return '%s: %s' % (self.name, '男' if self.sex else '女')


# stu1 = Student(1001, '骆昊', True, '四川成都')
# print(stu1)
# stu2 = Student(1002, '王大锤', True, '四川绵阳')
# students = [stu1, stu2]
client = redis.Redis(host='120.77.222.217', port=6379, password='1qaz2wsx')
if client.ping():
    # client.set('students', pickle.dumps(students))
    students = pickle.loads(client.get('students'))
    print(students)
